package com.justgame.project.service.just.controller;

import com.justgame.project.base.annotation.ProtectAccess;
import com.justgame.project.cloud.common.constant.Result;
import com.justgame.project.service.api.dto.JustGameAdditionDTO;
import com.justgame.project.cloud.common.entity.PageRequest;
import com.justgame.project.service.just.service.JustGameAdditionService;
import lombok.AllArgsConstructor;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/just/game-addition")
@AllArgsConstructor
public class JustGameAdditionController {

    private final JustGameAdditionService gameAdditionService;

    @GetMapping("/list")
    public Result<?> getList(PageRequest pageRequest, JustGameAdditionDTO dto) {
        return Result.OK(gameAdditionService.getList(pageRequest, dto));
    }

    @PostMapping("/save")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> addGameType(@Valid @RequestBody JustGameAdditionDTO dto) {
        return Result.OK(gameAdditionService.save(dto));
    }

    @DeleteMapping("/delete")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> deleteGameType(@RequestBody JustGameAdditionDTO dto) {
        return Result.OK(gameAdditionService.Delete(dto));
    }

    @PostMapping("/updateById")
    @RequiresRoles("admin")
    @ProtectAccess
    public Result<?> updateById(@RequestBody JustGameAdditionDTO dto) {
        return Result.OK(gameAdditionService.updateById(dto));
    }

}
